<?php
	namespace Qzn\View;
	class RegisterView {
		private $m_returnButton = "controller";
		private $m_setPassword = "password";
		private $m_setUsername = "username";
		private $m_setPasswordAgain = "passwordAgain";
		private $m_setEmail = "Email";
		private $m_registerButton = "register";
		
		/**
		 * @return string $html
		 */
		public function DoRegisterBox() {
			return "<div>
						<form method='post'>
							<fieldset>
								<label for='$this->m_setUsername'>Username: </label>
								<input name='$this->m_setUsername' type='text'/><br />
								<label for='$this->m_setPassword'>Password: </label>
								<input name='$this->m_setPassword' type='password'/><br />
								<label for='$this->m_setPasswordAgain'>Re-Type Password: </label>
								<input name='$this->m_setPasswordAgain' type='password'/><br />
								<label for='$this->m_setEmail'>Email: </label>
								<input name='$this->m_setEmail' type='text'/><br />
								<input name='$this->m_registerButton' type='submit' value='Register'>
							</fieldset>
						</form>
					</div>";
		}
		
		/**
		 * @return string $html
		 */
		public function DoAlreadyRegisterdBox() {
			return "<div>
						<a href='?'>You are already logged in, Return!</a>
					</div>";
		}
		
		/**
		 * Gets username from input data
		 * @return string Username from input
		 */
		public function GetUserName() {
			if(isset($_POST[$this->m_setUsername])) {
				return $_POST[$this->m_setUsername];
			}
			return NULL;
		}
		
		/**
		 * Gets password from input data
		 * @return string Password from input
		 */
		public function GetPassword() {
			if(isset($_POST[$this->m_setPassword])) {
				return $_POST[$this->m_setPassword];
			}
			return NULL;
		}
		
		/**
		 * Gets second password from input data
		 * @return string Password from input
		 */
		public function GetSecondPassword() {
			if(isset($_POST[$this->m_setPasswordAgain])) {
				return $_POST[$this->m_setPasswordAgain];
			}
			return NULL;
		}
		
		/**
		 * Gets email from input data
		 * @return string Email from input
		 */
		public function GetEmail() {
			if(isset($_POST[$this->m_setEmail])) {
				return $_POST[$this->m_setEmail];
			}
			return NULL;
		}

		/**
		 * Gets registerButton from input data
		 * @return boolean RegisterButton from input data
		 */
		public function TriedToRegister() {
			if(isset($_POST[$this->m_registerButton])) {
				return true;
			}
			return false;
		}
		
		/**
		 * Error handling
		 * @return string $html
		 * @param const $errorCode
		 */
		public function ErrorHandler($errorCode) {
			switch ($errorCode) {
				case \Qzn\Model\registerHandler::EVERYTHING_WENT_BETTER_THEN_EXPECTED:
						$html = "Register success!";
					break;
				case \Qzn\Model\registerHandler::USERNAME_TAKEN:
						$html = "Error: Username already taken.";
					break;
				case \Qzn\Model\registerHandler::PASSWORD_NO_MATCH:
						$html = "Error: Passwords did not match.";
					break;
				case \Qzn\Model\registerHandler::WRONG_EMAIL:
						$html = "Error: Email is not in a valid format.";
					break;
				case \Qzn\Model\registerHandler::PASSWORD_INVALID:
						$html = "Error: The passwords needs atleast 6 characters long.";
					break;
				case \Qzn\Model\registerHandler::INVALID_USERNAME:
						$html = "Error: The username should be between 3 and 36 characters long.";
					break;
			}
			return $html;
		}
	}
?>